package com.cssl.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cssl.domain.dto.AddComment;
import com.cssl.domain.dto.DtsCommentDto;
import com.cssl.domain.vo.DtsCommentVO;
import com.cssl.service.DtsCommentService;
import com.cssl.util.InfoCode;
import com.cssl.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/comment")
@Api(value = "评论接口", tags = "评论相关操作")
public class DtsCommentController {
    @Autowired
    private DtsCommentService service;

    @PostMapping("/getUserComment")
    @ApiOperation(value = "获得评论", notes = "接收参数DtsCommentDto")
    public Result getUserComment(@RequestBody DtsCommentDto dto) {
        return service.getUserComment(dto);
    }


    @PostMapping("/addComment")
    @ApiOperation(value = "新增评论", notes = "接收参数AddComment")
    public Result addComment(@RequestBody AddComment comment) {
        return service.addComment(comment);
    }

    @PostMapping("/getCommentVOGoodsList")
    @ApiOperation(value = "获取商品评论", notes = "用户名，商品id")
    public Result getCommentVOGoodsList(@RequestBody DtsCommentVO comment) {
        Map map = service.getCommentVOGoodsList(comment);
        if (ObjectUtil.isEmpty(map.get("list"))) {
            return Result.result(InfoCode.QUERY_EMPTY, InfoCode.MESSAGE_QUERY_EMPTY, null, System.currentTimeMillis());
        }
        return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, map, System.currentTimeMillis());
    }

    @PostMapping("/deleteComment")
    @ApiOperation(value = "删除商品评论", notes = "商品评论id")
    public Result deleteComment(@RequestBody Integer id) {
        Boolean flag = service.deleteComment(id) > 0;
        return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, flag, System.currentTimeMillis());
    }

}
